package com.smartcommunity.base.common;

import com.smartcommunity.service.common.CommonService;
import com.smartcommunity.utils.ApplicationContextHelper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassName: CommonController
 * @Description: 刷新redis缓存
 * @author: minsheng
 * @Date: 2019/1/3 13:50
 * @Company:
 * @version V1.5.0
 */
@RestController
@RequestMapping(value = "/common")
@Slf4j
public class CommonController {

    @Autowired
    private CommonService commonService;
    /**
     * @Description: 刷新redis缓存
     * @param:
     * @return:
     * @auther: minsheng
     * @date: 2018/12/13 11:01
     */
    @RequestMapping(value = "refreshAll")
    public void refreshAllCache(){
        CacheMap cacheMap = (CacheMap) ApplicationContextHelper.getBean(CacheMap.class);
        //commonService.clearAll();
        try {
            cacheMap.initCache();
        } catch (Exception e) {
            log.error("CommonController:refreshAllCache error ,",e);
        }
    }
    /**
     * @Description: 刷新小区数据redis缓存
     * @param:
     * @return:
     * @auther: minsheng
     * @date: 2018/12/13 11:02
     */
    @RequestMapping(value = "refreshVillage")
    public void refreshVillage(){
        commonService.refreshVillage();
    }
    /**
     * @Description: 清除缓存
     * @param: cachekey
     * @return:
     * @auther: minsheng
     * @date: 2018/12/13 11:02
     */
    @RequestMapping("/clearCache/{cacheName}/{cacheKey}")
    public void clearCache(@PathVariable("cacheName") String cacheName, @PathVariable("cacheKey")String cacheKey){
        //cacheSupport.clear(cacheName,cacheKey);
    }
}
